<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  admin_category.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-06-14.
//  Copyright 2011 lishuzu. All rights reserved.
// 
/**
* 分类设置
*/
class Admin_category extends CI_Controller
{
	
	function __construct()
	{
		parent::__construct();
 		$this->load->model('common/security_model');
		$this->load->model('category_model');
		if($this->security_model->isAdminLogin() === FALSE){
          showmessage('请登录', 'admin/login/index', 3);
		}
	}
	function index(){
		$data['categories'] = $this->category_model->get_categories();
		$this->load->template('admin/category_tpl', $data);
	}
	function edit_category(){
		$displayorders = $this->input->post('displayorder', true) ? $this->input->post('displayorder', true) : '';
		$names = $this->input->post('name', true) ? $this->input->post('name', true) : '';
		$newcats = $this->input->post('newcat', true) ? $this->input->post('newcat', true) : '';
		$newcatorders = $this->input->post('newcatorder', true) ? $this->input->post('newcatorder', true) : '';
		$batchsubmit = $this->input->post('batchsubmit', true);
		$newcat = $this->input->post('newcat', true);
		if ($batchsubmit) {
			foreach ($names as $catid => $name) {
				$updatedata = array(
					'name' =>$name,
					'displayorder' => $displayorders[$catid],
					);
				$this->db->where('catid', $catid);
				$this->db->update('category', $updatedata);
			}
			if ($newcats) {
				foreach ($newcats as $key => $newcat) {
					$insertdata = array(
						'name' => $newcat,
						'displayorder' => $newcatorders[$key],
						);
					$this->db->insert('category', $insertdata);
				}
			}
			showmessage('操作成功', 'admin/admin_category/index', 3);
		}
	}
}

?>